﻿using DBHelperModel;
using MyEntity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyDAL
{
    public class ProfessionInfoDAL
    {
        //新增专业
        public int Add(ProfessionInfoEntity pro)
        {
            string sql = "insert into ProfessionInfo(ProfessionName) values(@ProfessionName)";
            DBHepler.PrepareCmd(sql);
            DBHepler.SetParamter("ProfessionName", pro.ProfessionName);
            return DBHepler.ExecNonQuery();
        }


        //删除
        public int Delete(int ID)
        {
            string sql = "delete from ProfessionInfo where ProfessionID =@ProfessionID";
            DBHepler.PrepareCmd(sql);
            DBHepler.SetParamter("ProfessionID", ID);
            return DBHepler.ExecNonQuery();
        }

        //修改
        public int Update(ProfessionInfoEntity pro)
        {
            string sql = "update ProfessionInfo set ProfessionName = @ProfessionName where ProfessionID =@ProfessionID";
            DBHepler.PrepareCmd(sql);
            DBHepler.SetParamter("ProfessionName", pro.ProfessionName);
            return DBHepler.ExecNonQuery();
        }
        //列表

        public List<ProfessionInfoEntity> List()
        {
            DataTable dt = new DataTable();
            string sql = "select * from ProfessionInfo";
            DBHepler.PrepareCmd(sql);
            dt = DBHepler.ExecQuery();
            List<ProfessionInfoEntity> list = new List<ProfessionInfoEntity>();
            foreach (DataRow item in dt.Rows)
            {
                ProfessionInfoEntity entity = new ProfessionInfoEntity();
                entity.ProfessionID = Convert.ToInt32(item["ProfessionID"]);
                entity.ProfessionName = item["ProfessionName"].ToString();
                list.Add(entity);
            }
            return list;
        }


        //详情
        public ProfessionInfoEntity Detail(int ID)
        {
            DataTable dt = new DataTable();
            string sql = "select * from ProfessionInfo where ProfessionID =@ProfessionID";
            DBHepler.PrepareCmd(sql);
            DBHepler.SetParamter("ProfessionID", ID);
            dt=DBHepler.ExecQuery();
            if (dt.Rows.Count == 0)
            {
                return null;
            }
            ProfessionInfoEntity entity = new ProfessionInfoEntity();
            entity.ProfessionID = Convert.ToInt32(dt.Rows[0]["ProfessionID"].ToString());
            entity.ProfessionName = dt.Rows[0]["ProfessionName"].ToString();
            return entity;
        }
    }
}
